PREFIX  = /home/workspace/MegaMario/data
DATADIR = $(PREFIX)
#DATADIR = $(PREFIX)/share/$(TARGET)
CFLAGS  = -g -Wall -O2
CXXFLAGS= $(CFLAGS)
LIBS += -lSDL2 -lSDL2_mixer -lfreetype -lSDL2_ttf -lSDL2_image -lGL -lpng
DEFINES = -DDATADIR=\"$(DATADIR)/\"
OBJS    = src/bonus.o src/gamepad.o src/KillerFlower.o src/player.o \
  src/bowser.o      src/global.o    src/levels.o      src/spiny.o  \
  src/enemy.o       src/goomba.o    src/main.o        src/turtle.o \
  src/firecircle.o  src/goombabig.o src/menu.o \
  src/flybrett.o    src/opengl.o    src/iniparser.o   src/unixutils.o \
  src/functions.o   src/keyinput.o  src/particle.o src/CGamePlayStatics.o src/NpcItem.o src/FireBall.o src/CDamageType.o
TARGET  = megamario

#$(TARGET): $(OBJS)
	#$(CXX) $(LDFLAGS) -o $@ $^
$(TARGET): $(OBJS)
	$(CXX) -L/usr/local/lib -L/opt/sdl2_image/lib -L/opt/sdl2_mixer/lib -L/opt/sdl2_ttf/lib -o $@ $^ $(LIBS)

%.o: %.c
	$(CC) $(CFLAGS) $(DEFINES) -o $@ -c $<

%.o: %.cpp
	$(CXX) $(CXXFLAGS) $(DEFINES) -o $@ -c $<

install: $(TARGET)
	rm -fr $(DATADIR)
	mkdir -p $(PREFIX)/bin
	mkdir -p $(PREFIX)/share
	install -p -m 755 $(TARGET) $(PREFIX)/bin
	cp -a data $(DATADIR)
	# fix broken permission <sigh>
	chmod 755 $(DATADIR)/gfx/tiles/pipes/left
	for i in `find $(DATADIR) -name "*.PNG"`; do \
		mv $$i `echo $$i|sed s/PNG/png/`; \
	done
	for i in `find $(DATADIR) -name "*.JPG"`; do \
		mv $$i `echo $$i|sed s/JPG/jpg/`; \
	done
	
clean:
	rm -f $(OBJS) $(TARGET) *~ src/*~
